home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
cmln0885.arc
/
NIAL3.LTG
< prev
next >
Wrap
Text File
|
1986-02-27
|
2KB
|
42 lines
Nial Listing 3
Quicksort
qsort IS OPERATION A {
IF tally A <= 1 THEN
A
ELSE
Firstpart := A < first A sublist A;
Secondpart := A match first A sublist A;
Thirdpart := A > first A sublist A;
link (qsort Firstpart) Secondpart (qsort Thirdpart)
ENDIF }
Explanation:
IF tally A <= 1 THEN A gives the array argument if it has only 0
or 1 element.
Firstpar⌠ i≤ defineΣ t∩ bσ thσ element≤ oµ thσ arra∙ argumen⌠ ì
les≤ thaε thσ firs⌠ element« Secondpar⌠ i≤ thσ element≤ oµ thσ ì
arra∙ argumen⌠ whicΦ matcΦ thσ firs⌠ element« Thirdpar⌠ i≤ thσ ì
element≤ oµ thσ arra∙ argumen⌠ whicΦ arσ greate≥ thaε the firs⌠ ì
element« linδ yield≤ aε arra∙ consistinτ oµ thσ element≤ oµ it≤ ì
argument≤ linkeΣ together¼ firs⌠ thosσ les≤ thaε thσ firs⌠ ì
element¼ theε thosσ whicΦ matcΦ it¼ anΣ finall∙ thosσ greate≥ ì
thaε thσ firs⌠ element« qsor⌠ i≤ invokeΣ recursivel∙ oε thσ ì
Firstpar⌠ anΣ Thirdpar⌠ unti∞ the∙ arσ reduceΣ t∩ onl∙ onσ ì
element« Thσ sorteΣ arra∙ i≤ displayeΣ b∙ omittinτ ß semicoloε ì
froφ thσ expressioε linδ (qsor⌠ Firstpart⌐ Secondpar⌠ (qsor⌠ ì
Thirdpart)« Q'Nia∞ ha≤ ß sor⌠ primitive¼ s∩ thi≤ qsor⌠ operatioε ì
i≤ no⌠ needed bu⌠ i≤ provideΣ t∩ illustratσ recursion.
Timσ fo≥ aε arra∙ consistinτ oµ 10░ element≤ wa≤ 4▓ secì
usinτ thσ abovσ qsor⌠ operation anΣ 1.┤ sec usinτ thσ sor⌠ ì
predefineΣ operatioε oµ versioε 3.04« Iε versioε 3.0╢ anΣ ì
following¼ sor⌠ i≤ t∩ bσ ß predefineΣ transformer¼ anΣ it≤ ì
performancσ shoulΣ bσ improved.